<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="">
        <el-select
          v-model="queryParams.railwayName"
          placeholder="线名"
          clearable
          style="width: 140px"
        >
          <el-option
            v-for="dict in railwayNameobj"
            :key="dict.railwayName"
            :label="dict.railwayName"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-input
          v-model="queryParams.bridgeId"
          placeholder="桥号"
          clearable
          style="width: 140px"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList" style="width: 90px"
          >查询</el-button
        >
        <el-button @click="resetQuery" style="width: 90px">重置</el-button>
        <el-button type="primary" @click="handleQuery" style="width: 90px"
          >导出</el-button
        >
        <el-button type="primary" @click="handleAdd" style="width: 90px"
          >新增</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 表格数据 -->
    <el-table
      v-loading="loading"
      :data="railList"
      height="62vh"
      border
      @selection-change="selectiontab"
    >
      <el-table-column type="selection" label="全选" width="50" />
      <el-table-column label="序号" type="index" width="80" />
      <el-table-column label="线名" prop="railwayName" min-width="80" />
      <el-table-column label="上下行" prop="lineType" min-width="80" />
      <el-table-column label="线别" prop="railwayTypeName" min-width="80" />
      <el-table-column label="桥号" prop="bridgeCode" min-width="80" />
      <el-table-column label="桥名" prop="bridgeName" min-width="80" />
      <el-table-column label="孔别" prop="apertureType" min-width="80" />
      <el-table-column label="跨度" prop="span" min-width="80" />
      <el-table-column label="梁式样" prop="beamPattern" min-width="80" />
      <el-table-column label="直接数据" min-width="110">
        <template #default="scope">
          <div class="buttontext">
            <el-button link type="primary" @click="parameter(scope.row)"
              >参数</el-button
            >
            <el-button link type="primary" @click="meansFun(scope.row)"
              >资料</el-button
            >
          </div>
        </template>
      </el-table-column>
      <el-table-column label="关联数据" min-width="210">
        <template #default="scope">
          <div class="buttontext">
            <el-button link type="primary" @click="resumeUpdate(scope.row)"
              >作业履历</el-button
            >
            <el-button link type="primary" @click="deviceProblem(scope.row)"
              >设备问题</el-button
            >
            <el-button link type="primary" @click="businessFinance(scope.row)"
              >业财</el-button
            >
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="80">
        <template #default="scope">
          <div class="buttontext">
            <el-button link type="primary" @click="handDelete(scope.row.id)"
              >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加或修改用户配置对话框 -->
    <el-dialog :title="title" v-model="open" width="1300px" append-to-body>
      <el-form
        ref="userRef"
        :model="form"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">位置</span>
          <span class="rightx"></span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="单位名称" prop="unitId">
              <el-select
                filterable
                clearable
                style="width: 180px"
                v-model="form.unitId"
                placeholder="请选择"
              >
                <el-option
                  v-for="dict in unitNameobj"
                  :key="dict.id"
                  :label="dict.unitName"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="线名" prop="railwayId">
              <el-select
                filterable
                clearable
                style="width: 180px"
                v-model="form.railwayId"
                placeholder="请选择"
              >
                <el-option
                  v-for="dict in railwayNameobj"
                  :key="dict.id"
                  :label="dict.railwayName"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上下行" prop="lineTypeId">
              <el-select
                filterable
                clearable
                style="width: 180px"
                v-model="form.lineTypeId"
                placeholder="请选择"
              >
                <el-option
                  v-for="dict in progressTypeobj"
                  :key="dict.id"
                  :label="dict.progressType"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="线别" prop="railwayTypeId">
              <el-select
                filterable
                clearable
                style="width: 180px"
                v-model="form.railwayTypeId"
                placeholder="请选择"
              >
                <el-option
                  v-for="dict in lineTypeList"
                  :key="dict.id"
                  :label="dict.railwayModel"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="桥号" prop="bridgeId">
              <el-select
                filterable
                clearable
                style="width: 180px"
                v-model="form.bridgeId"
                placeholder="请选择"
                @change="getbridgeName"
              >
                <el-option
                  v-for="dict in bridgeList"
                  :key="dict.id"
                  :label="dict.bridgeId"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="桥名" prop="bridgeName">
              <el-input
                disabled
                v-model="form.bridgeName"
                placeholder="请输入桥名"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="孔别" prop="apertureType">
              <el-input v-model="form.apertureType" placeholder="请输入孔别" />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">特性</span>
          <span class="rightx"></span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="跨度" prop="span">
              <el-input v-model="form.span" placeholder="请输入跨度" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="换梁年代" prop="replacementDate">
              <el-date-picker
                style="width: 180px"
                format="YYYY/MM/DD"
                value-format="YYYY/MM/DD"
                v-model="form.replacementDate"
                type="datetime"
                placeholder="请选择换梁年代"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="梁底高程" prop="beamBaseElevation">
              <el-input
                type="number"
                v-model="form.beamBaseElevation"
                placeholder="请输入梁底高程"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="最大冲刷线" prop="maximumScourLine">
              <el-input
                v-model="form.maximumScourLine"
                placeholder="请输入最大冲刷线"
              />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="梁式样" prop="beamPattern">
              <el-input v-model="form.beamPattern" placeholder="请输入梁式样" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设计限界" prop="designLimit">
              <el-input
                v-model="form.designLimit"
                placeholder="请输入设计限界"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="梁种类" prop="beamType">
              <el-input v-model="form.beamType" placeholder="请输入梁种类" />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="梁重" prop="beamWeight">
              <el-input v-model="form.beamWeight" placeholder="请输入梁重" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="梁全长" prop="beamOverallLength">
              <el-input
                v-model="form.beamOverallLength"
                placeholder="请输入梁全长"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="主梁中心距" prop="kingpostCenterDistance">
              <el-input
                type="number"
                v-model="form.kingpostCenterDistance"
                placeholder="请输入主梁中心距"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="纵梁中心距" prop="longnCenterDistance">
              <el-input
                v-model="form.longnCenterDistance"
                placeholder="请输入纵梁中心距"
              /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="纵梁高" prop="longnHeight">
              <el-input
                type="number"
                v-model="form.longnHeight"
                placeholder="请输入纵梁高"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="设计活载" prop="designLiveLoad">
              <el-input
                v-model="form.designLiveLoad"
                placeholder="请输入设计活载"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="承载系数" prop="bearingCapacityFactor">
              <el-input
                type="number"
                v-model="form.bearingCapacityFactor"
                placeholder="请输入承载系数"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="挠度" prop="deflection">
              <el-input v-model="form.deflection" placeholder="请输入挠度" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="混凝土横梁隔板数" prop="betonBeamDiaphragmNum">
              <el-input
                v-model="form.betonBeamDiaphragmNum"
                placeholder="请输入混凝土横梁隔板数"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="道砟横宽度" prop="crossWidthOfBallast">
              <el-input
                type="number"
                v-model="form.crossWidthOfBallast"
                placeholder="请输入道砟横宽度"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">健康值</span>
          <span class="rightx"></span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="健康值" prop="healthIndex">
              <el-input v-model="form.healthIndex" placeholder="请输入健康值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="隐患等级" prop="hiddenDangerLevel">
              <el-input
                v-model="form.hiddenDangerLevel"
                placeholder="请输入隐患等级"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="存在问题" prop="existingProblem">
              <el-input
                v-model="form.existingProblem"
                placeholder="请输入存在问题"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="病害整治情况" prop="diseaseControlSituation">
              <el-input
                v-model="form.diseaseControlSituation"
                placeholder="请输入病害整治情况"
              /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="病害整治年份" prop="yearOfDiseaseControl">
              <el-input
                v-model="form.yearOfDiseaseControl"
                placeholder="请输入病害整治年份"
              /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="设备使用频率" prop="equipmentUsageFrequency">
              <el-input
                v-model="form.equipmentUsageFrequency"
                placeholder="请输入设备使用频率"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item
              label="设备综合效率(OEE)"
              prop="overallEquipmentEfficiency"
            >
              <el-input
                v-model="form.overallEquipmentEfficiency"
                placeholder="请输入设备综合效率(OEE)"
              /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item
              label="平均无故障工作时间(MTTF)"
              prop="meanTimeToFailure"
            >
              <el-input
                v-model="form.meanTimeToFailure"
                placeholder="请输入平均无故障工作时间(MTTF)"
              /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="平均修复时间(MTTR)" prop="meanTimeToRepair">
              <el-input
                v-model="form.meanTimeToRepair"
                placeholder="请输入平均修复时间(MTTR)"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">管理</span>
          <span class="rightx"></span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="区段" prop="sector">
              <el-input v-model="form.sector" placeholder="请输入区段" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工区" prop="workArea">
              <el-input v-model="form.workArea" placeholder="请输入工区" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="人员" prop="personnel">
              <el-input v-model="form.personnel" placeholder="请输入人员" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="包保责任人" prop="personInCharge">
              <el-input
                v-model="form.personInCharge"
                placeholder="请输入包保责任人"
              /> </el-form-item
          ></el-col>
          <el-col :span="8">
            <el-form-item label="备注" prop="comment">
              <el-input
                v-model="form.comment"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="divflex" v-if="parameterShow">
        <span class="leftx"></span>
        <span class="mainz">修改历史</span>
        <span class="rightx"></span>
      </div>
      <el-table
        :data="allBridgeChangeData"
        border
        height="300px"
        v-if="parameterShow"
      >
        <el-table-column label="序号" type="index" width="80" />
        <el-table-column
          label="指标名"
          prop="property"
          min-width="80"
        ></el-table-column>
        <el-table-column
          label="变更前指标值"
          prop="oldValue"
          min-width="80"
        ></el-table-column>
        <el-table-column
          label="变更后指标值"
          prop="newValue"
          min-width="80"
        ></el-table-column>
        <el-table-column
          label="变更时间"
          prop="createTime"
          min-width="80"
        ></el-table-column>
        <el-table-column
          label="操作用户名"
          prop="user"
          min-width="80"
        ></el-table-column>
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog
      title="设备问题"
      v-model="equipmentproblemShow"
      width="1200px"
      append-to-body
    >
      <p>故障</p>
      <div>
        <el-form :model="faultForm" ref="queryRef" :inline="true">
          <el-form-item label="故障时间">
            <el-select
              v-model="faultForm.lineId"
              placeholder="线名"
              clearable
              style="width: 140px"
            >
              <el-option
                v-for="dict in railwayNameobj"
                :key="dict.railwayName"
                :label="dict.railwayName"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="">
            <el-button type="primary" @click="faultSeek" style="width: 90px"
              >查找</el-button
            >
            <el-button @click="faultClear" style="width: 90px">清空</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="" style="width: 90px"
              >新增</el-button
            >
          </el-form-item>
        </el-form>
        <el-table :data="faultForm.tabledata" height="57vh" border>
          <el-table-column type="selection" label="全选" width="50" />
          <el-table-column label="故障编码" type="index" width="80" />
          <el-table-column label="故障描述" prop="railwayName" min-width="80" />
          <el-table-column label="故障类别" prop="lineType" min-width="80" />
          <el-table-column
            label="故障时间"
            prop="centreMileage"
            min-width="80"
          />
          <el-table-column
            label="处理状态"
            prop="startingMileage"
            min-width="80"
          />
          <el-table-column
            label="维修方案"
            prop="destinationMileage"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="维修日期"
            prop="bridgeId"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="作业流程"
            prop="bridgeName"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="维修负责人"
            prop="bridgeSpanNum"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="故障处理耗时"
            prop="kingpostNum"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="故障来源"
            prop="supportNum"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="上报用户"
            prop="foundationPilesNum"
            min-width="80"
          ></el-table-column>
          <el-table-column label="操作" min-width="100">
            <template #default="scope">
              <div class="buttontext">
                <el-button link type="primary" icon="el-icon-edit"
                  >修改</el-button
                >
                <el-button link type="primary">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <p>超限</p>
      <div>
        <el-form :model="faultForm" ref="queryRef" :inline="true">
          <el-form-item label="更新时间">
            <el-select
              v-model="faultForm.lineId"
              placeholder="线名"
              clearable
              style="width: 140px"
            >
              <el-option
                v-for="dict in railwayNameobj"
                :key="dict.railwayName"
                :label="dict.railwayName"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="">
            <el-button type="primary" @click="faultSeek" style="width: 90px"
              >查找</el-button
            >
            <el-button @click="faultClear" style="width: 90px">清空</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="" style="width: 90px"
              >新增</el-button
            >
          </el-form-item>
        </el-form>
        <el-table :data="railList" height="57vh" border>
          <el-table-column type="selection" label="全选" width="50" />
          <el-table-column label="序号" type="index" width="80" />
          <el-table-column
            label="标示位置-公里"
            prop="railwayName"
            min-width="80"
          />
          <el-table-column label="标示位置-米" prop="lineType" min-width="80" />
          <el-table-column
            label="线路特征"
            prop="centreMileage"
            min-width="80"
          />
          <el-table-column
            label="处理结果"
            prop="startingMileage"
            min-width="80"
          />
          <el-table-column
            label="处理时间"
            prop="destinationMileage"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="天窗命令号"
            prop="bridgeId"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="负责人"
            prop="bridgeName"
            min-width="80"
          ></el-table-column>
          <el-table-column label="操作" min-width="100">
            <template #default="scope">
              <div class="buttontext">
                <el-button link type="primary" icon="el-icon-edit"
                  >修改</el-button
                >
                <el-button link type="primary">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <p>告警</p>
      <div>
        <el-form :model="faultForm" ref="queryRef" :inline="true">
          <el-form-item label="报警时间">
            <el-select
              v-model="faultForm.lineId"
              placeholder="线名"
              clearable
              style="width: 140px"
            >
              <el-option
                v-for="dict in railwayNameobj"
                :key="dict.railwayName"
                :label="dict.railwayName"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="">
            <el-button type="primary" @click="faultSeek" style="width: 90px"
              >查找</el-button
            >
            <el-button @click="faultClear" style="width: 90px">清空</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="" style="width: 90px"
              >新增</el-button
            >
          </el-form-item>
        </el-form>
        <el-table :data="railList" height="57vh" border>
          <el-table-column type="selection" label="全选" width="50" />
          <el-table-column label="报警序号" type="index" width="80" />
          <el-table-column
            label="标示位置-公里"
            prop="railwayName"
            min-width="80"
          />
          <el-table-column label="标示位置-米" prop="lineType" min-width="80" />
          <el-table-column
            label="线路特征"
            prop="centreMileage"
            min-width="80"
          />
          <el-table-column
            label="处理结果"
            prop="startingMileage"
            min-width="80"
          />
          <el-table-column
            label="处理时间"
            prop="destinationMileage"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="天窗命令号"
            prop="bridgeId"
            min-width="80"
          ></el-table-column>
          <el-table-column
            label="负责人"
            prop="bridgeName"
            min-width="80"
          ></el-table-column>
          <el-table-column label="操作" min-width="100">
            <template #default="scope">
              <div class="buttontext">
                <el-button link type="primary" icon="el-icon-edit"
                  >修改</el-button
                >
                <el-button link type="primary">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <p>在线监测/控制</p>
    </el-dialog>
    <el-dialog
      title="业财"
      v-model="businessFinanceShow"
      width="1200px"
      append-to-body
    >
      <p>
        <span>经济投入</span>
        <el-button
          link
          type="primary"
          @click="addEconomyTableData(scope.row.id)"
          >新增物资</el-button
        >
      </p>
      <el-table :data="economyTableData" height="300px" border>
        <el-table-column label="编号" type="index" width="80" />
        <el-table-column label="物资名称" prop="railwayName" />
        <el-table-column label="物资类型" prop="lineType" />
        <el-table-column label="物资单价" prop="centreMileage" />
        <el-table-column label="采购数量" prop="startingMileage" />
        <el-table-column label="采购总价" prop="destinationMileage" />
      </el-table>
      <p>
        <span>财务台账</span>
        <el-button link type="primary" @click="handDeletez(scope.row.id)"
          >新增物资</el-button
        >
      </p>
      <el-table :data="ledgerTabledata" height="300px" border>
        <el-table-column label="编号" type="index" width="80" />
        <el-table-column label="物资名称" prop="railwayName" />
        <el-table-column label="物资类型" prop="lineType" />
        <el-table-column label="物资单价" prop="centreMileage" />
        <el-table-column label="库存数量" prop="startingMileage" />
        <el-table-column label="库存总价" prop="destinationMileage" />
        <el-table-column label="消耗标准" prop="centreMileage" />
        <el-table-column label="实际消耗量" prop="startingMileage" />
        <el-table-column label="消耗总价" prop="destinationMileage" />
      </el-table>
    </el-dialog>
    <el-dialog
      draggable
      title="资料"
      v-model="meansopen"
      width="1300px"
      append-to-body
      @close="closefun"
    >
      <means :forma="formam" parentName="孔跨单元" v-if="meansopen"></means>
    </el-dialog>
  </div>
</template>

<script setup name="Bridge">
import means from "@/components/railmodle/means.vue";
import { useContent } from "@/mixin/index.js";
const {
  meansopen,
  meansFun,
  formam,
  closefun,
  resumeUpdate,
  deviceProblem,
  businessFinance,
} = useContent();
import {
  getselectManBridgeHoleSpanElementList,
  addinsertManBridgeHoleSpanElement,
  updateeditManBridgeHoleSpanElement,
  deleteManBridgeHoleSpanElementById,
  getselectManBridgeHoleSpanElementById,
  getSelectManBridgeEditRecordListApi,
  listBridgeRailapi,
} from "@/api/main/bridge.js";
import {
  selectManBasicUnitListapi,
  selectManBasicRailwayListapi,
  selectManBasicprogressTypeListapi,
  selectManBasicRailwayModelListapi,
} from "@/api/main/api.js";
import { reactive, ref, toRefs } from "vue";
const { proxy } = getCurrentInstance();
const title = ref("新增");
const loading = ref(true);
const open = ref(false);
const equipmentproblemShow = ref(false);
const businessFinanceShow = ref(false);

const parameterShow = ref(false);

defineExpose({ getList });
const emit = defineEmits(["parentCount"]);

const data = reactive({
  faultForm: {
    lineId: "",
    tabledata: [],
  },
  railList: [],
  selecttabList: [],
  //单位名称列表数据
  unitNameobj: [],
  //线名数据列表
  railwayNameobj: [],
  //行别数据列表
  progressTypeobj: [],
  // 线别
  lineTypeList: [],
  // 全桥
  bridgeList: [],
  form: {},
  queryParams: {
    pageNum: "1",
    pageSize: "10",
    railwayName: "",
    bridgeId: "",
  },
  rules: {
    unitId: [
      { required: true, message: "单位不能为空", trigger: ["blur", "change"] },
    ],
    railwayId: [
      { required: true, message: "线名不能为空", trigger: ["blur", "change"] },
    ],
    bridgeId: [
      { required: true, message: "桥号不能为空", trigger: ["blur", "change"] },
    ],
    apertureType: [
      {
        required: true,
        message: "孔别号不能为空",
        trigger: ["blur", "change"],
      },
    ],
  },
  allBridgeChangeData: [],
  economyTableData: [],
  ledgerTabledata: [],
});

const {
  faultForm,
  queryParams,
  railList,
  selecttabList,
  form,
  rules,
  unitNameobj,
  railwayNameobj,
  progressTypeobj,
  lineTypeList,
  bridgeList,
  allBridgeChangeData,
  economyTableData,
  ledgerTabledata,
} = toRefs(data);

const pageNumparent = ref(undefined);
const pageSizeparent = ref(undefined);

function init() {
  getLineDataList();
  getUnitDataList();
  getxbData();
  getLineTypeList();
  getAllBridgeData();
  getList();
}
init();
/** 查询列表 */

function getList(pageNum, pageSize) {
  loading.value = true;
  if (pageNum != undefined || pageSize != undefined) {
    pageNumparent.value = pageNum;
    pageSizeparent.value = pageSize;
    queryParams.value.pageNum = pageNum == undefined ? 1 : pageNum;
    queryParams.value.pageSize = pageSize == undefined ? 10 : pageSize;
  } else {
    queryParams.value.pageNum =
      pageNumparent.value == undefined ? "1" : pageNumparent.value;
    queryParams.value.pageSize =
      pageSizeparent.value == undefined ? "10" : pageSizeparent.value;
  }
  getselectManBridgeHoleSpanElementList({
    pageNum: queryParams.value.pageNum,
    pageSize: queryParams.value.pageSize,
    railwayId: queryParams.value.railwayName,
    bridgeCode: queryParams.value.bridgeId,
  }).then((res) => {
    if (res.code == 200) {
      data.railList = res.data;
    }
    loading.value = false;
    emit("parentCount", res.count);
  });
}
/** 查询基础数据-线名数据列表 */
function getLineDataList() {
  selectManBasicRailwayListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      railwayNameobj.value = res.data;
      console.log(railwayNameobj.value);
    }
  });
}
/** 查询基础数据-单位数据列表 */
function getUnitDataList() {
  selectManBasicUnitListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      unitNameobj.value = res.data;
      console.log(unitNameobj.value);
    }
  });
}
/** 查询基础数据-行别数据列表 */
function getxbData() {
  selectManBasicprogressTypeListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      progressTypeobj.value = res.data;
      console.log(progressTypeobj.value);
    }
  });
}
/** 查询基础数据-线别数据列表 */
function getLineTypeList() {
  selectManBasicRailwayModelListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      lineTypeList.value = res.data;
    }
  });
}

/** 查询全桥数据-桥号数据列表 */
function getAllBridgeData() {
  listBridgeRailapi().then((res) => {
    if (res.code == 200) {
      bridgeList.value = res.data;
    }
  });
}

/* 删除单行数据 */
function handDelete(row) {
  deleteManBridgeHoleSpanElementById({ id: row }).then((res) => {
    if (res.code == 200) {
      proxy.$modal.msgSuccess("删除成功");
      getList();
    }
  });
}

/** 重置操作表单 */
function reset() {
  form.value = {
    id: "",
    unitId: "",
    railwayId: "",
    lineTypeId: "",
    railwayType: "",
    bridgeId: "",
    bridgeName: "",
    apertureType: "",
    span: "",
    replacementDate: "",
    beamBaseElevation: "",
    maximumScourLine: "",
    beamPattern: "",
    designLimit: "",
    beamType: "",
    beamWeight: "",
    beamOverallLength: "",
    kingpostCenterDistance: "",
    longnCenterDistance: "",
    longnHeight: "",
    designLiveLoad: "",
    bearingCapacityFactor: "",
    deflection: "",
    betonBeamDiaphragmNum: "",
    crossWidthOfBallast: "",
    healthIndex: "",
    hiddenDangerLevel: "",
    existingProblem: "",
    diseaseControlSituation: "",
    yearOfDiseaseControl: "",
    equipmentUsageFrequency: "",
    overallEquipmentEfficiency: "",
    meanTimeToFailure: "",
    meanTimeToRepair: "",
    sector: "",
    workArea: "",
    personnel: "",
    personInCharge: "",
    comment: "",
  };
  proxy.resetForm("userRef");
}
/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "新增";
  parameterShow.value = false;
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["userRef"].validate((valid) => {
    if (valid) {
      //单位名称列表数据
      unitNameobj.value.forEach((item) => {
        if (form.value.unitId == item.id) {
          form.value.unitName = item.unitName;
        }
      });
      //线名数据列表
      railwayNameobj.value.forEach((item) => {
        if (form.value.railwayId == item.id) {
          form.value.railwayName = item.railwayName;
        }
      });
      //行别数据列表
      progressTypeobj.value.forEach((item) => {
        if (form.value.lineTypeId == item.id) {
          form.value.lineType = item.progressType;
        }
      });
      // 线别
      lineTypeList.value.forEach((item) => {
        if (form.value.railwayTypeId == item.id) {
          form.value.railwayTypeName = item.railwayModel;
        }
      });
      if (form.value.id) {
        updateeditManBridgeHoleSpanElement(form.value).then((res) => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addinsertManBridgeHoleSpanElement(form.value).then((res) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}
function selectiontab(row) {
  selecttabList.value = row;
}
// 导出
function handleQuery() {
  const arrid = [];
  for (let i = 0; i < selecttabList.value.length; i++) {
    arrid.push(selecttabList.value[i].id);
  }
  proxy.download1(
    "/facility-manage/element/exportExcel",
    arrid,
    `孔跨单元${new Date().getTime()}.xlsx`
  );
}
//重置
function resetQuery() {
  queryParams.value = {
    railwayName: "",
    bridgeId: "",
  };
  getList();
}
// 查看参数
function parameter(rows) {
  getselectManBridgeHoleSpanElementById({
    id: rows.id,
  }).then((res) => {
    form.value = res.data;
    getSelectManBridgeEditRecordListApi({
      bridgeId: rows.id,
    }).then((res1) => {
      allBridgeChangeData.value = res1.data;
      title.value = "参数";
      open.value = true;
      parameterShow.value = true;
    });
  });
}
// 获取桥名
function getbridgeName() {
  bridgeList.value.forEach((item) => {
    if (form.value.bridgeId == item.id) {
      form.value.bridgeName = item.bridgeName;
    }
  });
}
// // 设备
// function equipmentproblem() {
//   equipmentproblemShow.value = true;
// }
// // 业财
// function businessFinance() {
//   businessFinanceShow.value = true;
// }
</script>

<style scoped lang="scss">
.divflex {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .leftx {
    width: 45%;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    border-bottom-color: #e8e8e8;
    margin-top: 3px;
  }

  .mainz {
    font-weight: 400;
    font-style: normal;
    font-size: 16px;
    line-height: 24px;
  }

  .rightx {
    width: 45%;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    border-bottom-color: #e8e8e8;
    margin-top: 3px;
  }
}

.buttontext {
  .el-button:hover {
    // text-decoration: line-through !important;
  }
}

.el-form--inline .el-form-item.formitemcla {
  margin-right: 5px !important;
}
</style>
